<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2023/4/13
 * Time: 下午2:05
 */

namespace app\web\controller;

use app\api\controller\v2\Auth;
use app\common\cachemodel\zl5\Zl5ExplainTitle;
use app\common\lib\Util;
use app\common\model\Recode;
use think\Controller;
use think\Env;
use think\Exception;

/**
 * 本命解读聊天
 * Class NatalChat
 * @package app\web\controller
 */
class NatalChat extends Controller
{
    /**
     * 合并ai那边的问题
     */
    public function index()
    {
        $h = input('h/d', 0);
        $rid = input('rid/d', 0);
        $appType = $this->request->header('app-type', 'h5');
        // 校验token
        try
        {
            $auth = new Auth();
            $auth->checkRequestAuth();
            $uid = $auth->user['id'];
        }
        catch (Exception $e)
        {
            //用户未登录、没有档案、校验失败的情况
            $uid = 0;
        }
        $recordInfo = (new Recode())->getRecode(['id' => $rid]);
        $avatar = Util::getImgUrl($recordInfo['avatar']);

        // 合并新版数据
        if (in_array($appType, ['ios', 'android'], true) && Util::CheckAppVersion('2.9.10') !== '小')
        {
            // 查询新版问题数据
            $question = (new Zl5ExplainTitle())->getQuestionData2();
            $tplName = 'index';
        } else
        {
            // 查询旧版问题数据
            $question = array_values((new Zl5ExplainTitle())->getQuestionData());
            $tplName = 'index2';
        }

        $data = [
            'rid' => $rid,
            'question' => $question,
            'avatar' => Util::getImgUrl($avatar), // 用户头像
            'share_url' => Env::get('host.domain') . '/web/astro_explain_new/explainChatIntro',
        ];

        return $this->fetch($tplName, [
            'page_title' => Util::IsHuawei() ? '准了星图解读' : '准了星座解读',
            'chat_top_img' =>Util::IsHuawei() ? 'chat-top1.png' : 'chat-top.png',
            'h' => $h,
            'data' => $data,
            'app_type' => $appType,
        ]);
    }
}
